package com.wxmit.ot.gen.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wxmit.ot.base.core.OtBaseServiceImpl;
import com.wxmit.ot.gen.domain.GenGroupItem;
import com.wxmit.ot.gen.mapper.GenGroupItemMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collection;
import java.util.List;

/**
 * GenGroupService
 *
 * @author huangxiong
 * @version V1.0
 * @date 2023/2/22 10:44
 */
@Service
@RequiredArgsConstructor
public class GenGroupItemService extends OtBaseServiceImpl<GenGroupItemMapper, GenGroupItem> {

    public List<GenGroupItem> listByGroupId(Long groupId) {
        LambdaQueryWrapper<GenGroupItem> lambdaQuery = getLambdaQuery();
        lambdaQuery.eq(GenGroupItem::getGroupId,groupId);
        return baseMapper.selectList(lambdaQuery);
    }

    public List<Long> listIdByGroupId(Long groupId) {
        LambdaQueryWrapper<GenGroupItem> lambdaQuery = getLambdaQuery();
        lambdaQuery.select(GenGroupItem::getId);
        lambdaQuery.eq(GenGroupItem::getGroupId,groupId);
        return baseMapper.selectList(lambdaQuery).map(GenGroupItem::getId).toList();
    }

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.SUPPORTS)
    public void removeBatchByGroupIds(Collection<?> groupIds) {
        LambdaQueryWrapper<GenGroupItem> lambdaQuery = getLambdaQuery();
        lambdaQuery.in(GenGroupItem::getGroupId,groupIds);
        baseMapper.delete(lambdaQuery);
    }
}
